function get(url,params,type,header){
    let temp = []
    for(key in params){
        temp.push(`${key}=${params[key]}`)
    }
  
    return new Promise((resolve,reject)=>{
        const xhr = new XMLHttpRequest()
    xhr.open('get',`${url}?${temp.join("&")}`)
    xhr.onreadystatechange= function(){
        if(xhr.readyState===4){
            if(xhr.status===200){
                let res = xhr.responseText
                if(type==='json') res = JSON.parse(res)
                resolve(res)
            }else{
                reject(xhr.status)
            }
        }
    }
    for(key in header){
        xhr.setRequestHeader(key,header[key])
    }
    xhr.send()
    
    })
   }


   function post(url,params,type,headers){
    return new Promise((resolve,reject)=>{
        const xhr = new XMLHttpRequest()
    xhr.open('post',`${url}`)
    xhr.onreadystatechange= function(){
        if(xhr.readyState===4){
            if(xhr.status===200){
                let res = xhr.responseText
                if(type==='json') res = JSON.parse(res)
                resolve(res)
            }else{
                reject(xhr.status)
            }
        }
    }
    xhr.setRequestHeader('content-type','application/x-www-form-urlencoded')
    for(key in headers){
        setRequestHeader(key,headers[key])
    }
    xhr.send(params)
    
    })

   }